using Circus.CodeEditor;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace Circus.CodeEditor.CodeCompletion
{
	[DesignTimeVisible(false), ToolboxItem(false)]
	public class CompletionEdit : UserControl
	{
		internal class CompletionLabel : Label
		{
			private CompletionEdit owner;
			public override string Text
			{
				get
				{
					return base.Text;
				}
				set
				{
					if (base.Text != value)
					{
						base.Text = value;
						this.owner.UpdateSize();
					}
				}
			}
			public CompletionLabel(CompletionEdit owner)
			{
				this.owner = owner;
			}
		}
		private TextBox editBox;
		private Label label;
		private Label pathLabel;
		private Painter painter;
		public TextBox EditBox
		{
			get
			{
				return this.editBox;
			}
		}
		public Label Label
		{
			get
			{
				return this.label;
			}
		}
		public Label PathLabel
		{
			get
			{
				return this.pathLabel;
			}
		}
		protected void DoKeyPress(object sender, KeyPressEventArgs e)
		{
			e.Handled = (e.KeyChar == '\n' || e.KeyChar == '\r' || e.KeyChar == '\u001b');
		}
		public CompletionEdit()
		{
			this.painter = new Painter();
			base.Height = this.Font.Height;
			this.editBox = new TextBox();
			this.editBox.Multiline = false;
			this.editBox.Parent = this;
			this.editBox.BorderStyle = BorderStyle.None;
			this.editBox.Top = 0;
			this.editBox.KeyPress += new KeyPressEventHandler(this.DoKeyPress);
			this.pathLabel = new CompletionEdit.CompletionLabel(this);
			this.pathLabel.Parent = this;
			this.pathLabel.Font = new Font(this.PathLabel.Font, FontStyle.Underline);
			this.pathLabel.Top = 0;
			this.pathLabel.AutoSize = true;
			this.pathLabel.ForeColor = EditConsts.DefaultUrlForeColor;
			this.label = new Label();
			this.label.Parent = this;
			this.label.Font = new Font(this.label.Font, FontStyle.Bold);
			this.label.Top = 0;
			this.label.AutoSize = true;
			this.BackColor = EditConsts.DefaultSnippetBackColor;
			this.editBox.BackColor = EditConsts.DefaultSnippetBackColor;
			this.label.BackColor = EditConsts.DefaultSnippetBackColor;
			this.pathLabel.BackColor = EditConsts.DefaultSnippetBackColor;
			this.UpdateSize();
		}
		public void UpdateSize()
		{
		    this.painter.font = this.pathLabel.Font;
		    int num = Math.Max((this.pathLabel.Width - this.painter.measureString(this.pathLabel.Text)) / 2, 0);
			int num2 = this.label.Width + this.pathLabel.Width - num;
			int width = base.ClientRectangle.Width;
			this.label.Left = Math.Min(width - 2 - num2, 0);
			this.pathLabel.Left = this.label.Left + this.label.Width;
			this.editBox.Left = this.pathLabel.Left + this.pathLabel.Width - num;
			this.editBox.Width = width - this.editBox.Left;
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (this.editBox != null)
				{
					this.editBox.KeyPress -= new KeyPressEventHandler(this.DoKeyPress);
					this.editBox = null;
				}
			}
			base.Dispose(disposing);
		}
	
	}
}
